<?php
echo $this->Html->script('instituicao');
echo $this->Html->script('servico');
?>
<div id="msg"></div>
<form action="/siscel/instituicaoLabs/pesquisar" id="INSTITUICAOPesquisarForm" method="post">
    <fieldset>
        <legend>Unidades</legend>
        <input type="hidden" name="_method" value="POST"/>
        <table width="98%" border="0" cellspacing="0" cellpadding="2">
            <thead> 
                <th colspan="3">
                    <b>INFORMAÇÕES BÁSICAS</b>
                </th>
                <th style="text-align: right;">
                    <img src="/siscel/img/bt_apagar.gif" id="" onclick="Instituicao.excluirIntituicao('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>');"/>
                    <img src="/siscel/img/bt_lapis.gif" id="" onclick="Instituicao.redireciona('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>');"/>
                </th>
            </thead>
            <tr style="background-color:<?php //echo $cor; ?>;">
                <td rowspan="4" style="width:5%;align:center;">
                    <a href="/siscel/instituicaoLabs/visualizar/<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>">
                        <?php
                            if(!empty($arrInstituicao['INSTITUICAOLAB']['IM_FOTO'])){
                                $this->Siscel->foto($arrInstituicao['INSTITUICAOLAB']['IM_FOTO'], 70, 70);
                            }else{
                                echo $this->Html->image('/img/perfil.jpg', array('width' => '70', 'height' => '70', 'label' => null, 'style' => 'border: 0;margin: 4px 8px;'));
                            }
                        ?>
                    </a>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?php echo $this->Form->input('INSTITUICAO.NM_INST', array('type' => 'text', 'label' => 'Nome', 'id' => 'txtNome', 'class' => 'campoAlfa', 'size' => "30", 'maxlength' => "100", 'value' => $arrInstituicao['INSTITUICAOLAB']['NM_INST'], 'readonly'=>'readonly' )); ?>
                </td>
                <td colspan="2">
                    <?php echo $this->Form->input('INSTITUICAO.NM_INST_CURTO', array('type' => 'text', 'label' => 'Nome curto', 'id' => 'txtNomeCurto', 'class' => 'campoAlfa', 'size' => "20", 'maxlength' => "15", 'value' => $arrInstituicao['INSTITUICAOLAB']['NM_INST_CURTO'],'readonly'=>'readonly')); ?>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <b>Subordinação:</b>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <b>Email: </b> <?php echo $arrInstituicao['INSTITUICAOLAB']['DS_EMAIL_PRINCIPAL'].' '.$arrInstituicao['INSTITUICAOLAB']['DS_EMAIL_SECUNDARIO'] ?>
                </td>
            </tr>
        </table>
    </fieldset>
</form>
<div id="dialog"></div>
<div id="dialogNovoRestTec"></div>
<div id="divCadastroComplementar">
    <table width="98%" border="0" cellspacing="0" cellpadding="2">
        <thead>
            <th>
                <b>INFORMAÇÕES COMPLEMENTARES</b>
            </th>
            <th style="text-align: right;">
                <img src="/siscel/img/bt_lapis.gif" id="addComplementarInstituicao" onclick="Instituicao.dadosComplementares('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>',true);"/>
            </th>
        </thead>
        <tbody>
            <tr>
                <td title="<?php echo h($arrInstituicao[0]['TELEFONES']); ?>" colspan="2">
                    <b>Telefones:</b> <?php echo substr(h($arrInstituicao[0]['TELEFONES']), 0, 120).' ...'; ?>
                </td>
            </tr>
            <tr>
                <td title="<?php echo h($arrInstituicao[0]['ENDERECOS']); ?>" colspan="2">
                    <b>Endereços:</b> <?php echo substr(h($arrInstituicao[0]['ENDERECOS']), 0, 120).' ...'; ?>
                </td>
            </tr>
        <tbody>
    </table>
    <div id="tabs">
        <ul>
            <li style="width: 24%;"><a href="#tabs-1">Dados técnicos</a></li>
            <li style="width: 24%;"><a href="#tabs-2">Médicos</a></li>
            <li style="width: 24%;"><a href="#tabs-3">Pacientes</a></li>
            <li style="width: 24%;"><a href="#tabs-4">Contatos</a></li>
        </ul>
        
        <div id="tabs-1">
            <table width="98%" border="0" cellspacing="0" cellpadding="2" class="dataTable display">
                <thead>
                    <th colspan="4">
                        <b>SERVIÇOS</b>
                    </th>
                    <th style="text-align: right;">
                        <img src="/siscel/img/bt_lapis.gif" id="addComplementarMedico" onclick="Instituicao.servicos('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>');"/>
                    </th>
                </thead>
                <tbody>
                    <?php foreach($arrServicos as $s){ ?>
                        <tr>
                            <td style="width: 5%;">
                                <?php echo $this->Form->input('servicos', array('type' => 'checkbox', 'label' => '', 'value' => '', 'checked'=>true, 'onclick'=>"Servico.excluiServico('".h($s['RelacionamentoInstituicaoServico']['CO_SERVICO'])."', '".h($s['RelacionamentoInstituicaoServico']['CD_INST_LAB'])."', this);" )); ?>
                            </td>
                            <td>
                                <?php echo h($s['Servico']['DS_SERVICO']); ?>
                            </td>
                            <td>
                                <?php echo date("d/m/Y", strtotime(h($s['RelacionamentoInstituicaoServico']['DT_ATIV_LOGISTICA']))); ?>
                            </td>
                            <td>
                                <?php echo h($s['Doenca']['DS_DOENCA']); ?>
                            </td>
                            <td style="text-align: right;">
                                <?php echo $this->Siscel->tipoServico($s['Servico']['TP_SERVICO']); ?>
                            </td>
                        </tr>
                    <?php } ?>
                <tbody>
            </table>
            <table width="98%" border="0" cellspacing="0" cellpadding="2" class="dataTable">
                <thead>
                    <th colspan="2">
                        <b>RESPONSÁVEIS TÉCNICOS</b>
                    </th>
                    <th style="text-align: right;">
                        <img src="/siscel/img/bt_lapis.gif" id="addComplementarMedico" onclick="Instituicao.respTecnicos('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>');"/>
                    </th>
                </thead>
                <tbody>
                    <?php  if(!empty ($arrRespTecnicos)){
                    foreach($arrRespTecnicos as $r){ ?>
                        <tr>
                            <td style="width: 5%;">
                                <?php echo $this->Form->input('servicos', array('type' => 'checkbox', 'label' => '', 'value' => '', 'checked'=>true, 'onclick'=>"Servico.excluiServico('".h($s['RelacionamentoInstituicaoServico']['CO_SERVICO'])."', '".h($s['RelacionamentoInstituicaoServico']['CD_INST_LAB'])."', this);" )); ?>
                            </td>
                            <td>
                                <?php echo h($r['RESPONSAVELTECNICOLIBEXAME']['NO_RESPONSAVEL']); ?>
                            </td>
                            <td>
                                <?php echo h($r['ResponsavelInstituicaoServico']['NU_CONSELHO'].'/'.$r['UF']['NM_UF'].' - '.$r['CBO']['DS_CBO'].' - CNSUS:'.$r[0]['CNSUS']); ?>
                            </td>
                        </tr>
                    <?php } 
                    } ?>
                <tbody>
            </table>
        </div>

        <div id="tabs-2">
            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                    <th>
                        MÉDICOS
                    </th>
                </thead>
                <tbody>
                    <?php if(!empty ($arrMedicos)){
                        foreach ($arrMedicos as $v) { ?>
                        <tr>
                            <td style="width:5%;">
                                <?php
                                    if(!empty($v['Medico']['IM_FOTO'])){
                                        $this->Siscel->foto($v['Medico']['IM_FOTO'], 70, 70);
                                    }else{
                                        echo $this->Html->image('/img/perfil.jpg', array('width' => '70', 'height' => '70', 'label' => null, 'style' => 'border: 0;margin: 4px 8px;'));
                                    }
                                ?>
                            </td>
                            <td><b>Nome:</b><?php echo $v['Medico']['NM_MEDIC'] ?> <b>CPF:</b><?php echo $v['Medico']['CPF_MEDIC'] ?> <b>Nome:</b><?php echo $v['Medico']['CD_CRM'].'/'.$v['Uf']['NM_UF'] ?></td>
                            <td><b>Unidades:</b><?php echo $v[0]['UNIDADES']?></td>
                        </tr>
                    <?php } 
                    }else{ ?>
                        <tr>
                            <td>Sem registro</td>
                        </tr>
                    <?php } ?>
                <tbody>
            </table>
        </div>

        <div id="tabs-3">
            <table width="98%" border="0" cellspacing="0" cellpadding="2">
                <thead>
                    <th>
                        PACIENTES
                    </th>
                </thead>
                <tbody>
                    <?php if(!empty ($arrPacientes)){
                        foreach ($arrPacientes as $v) { ?>
                        
                    <?php }
                    }else{ ?>
                        <tr>
                            <td>Sem registro</td>
                        </tr>
                    <?php } ?>
                <tbody>
            </table>
        </div>

        <div id="tabs-4">
            <div class="button">
                <input  type="button" value="Novo" onclick="Instituicao.novoContato(<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']) ?>)"/>
            </div>
            <table width="98%" border="0" cellspacing="0" cellpadding="2" class="dataTable">
                <thead>
                    <th colspan="3">
                        CONTATOS
                    </th>
                </thead>
                <tbody>
                    <?php
                    if(!empty ($arrContatos)){
                        foreach($arrContatos as $v){?>
                            <tr id="row_<?php echo h($v['RelacionamentoContatoInsLabServico']['CO_SEQ_CONTATO_INST_LAB']); ?>">
                                <td>
                                    <div style="width: 100%">
                                        <div>
                                            <table style="width: 100%;border: 0;" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td>
                                                        <b>Nome: </b><?php echo h($v['RelacionamentoContatoInsLabServico']['NO_FUNCIONARIO']) ?>
                                                    </td>
                                                    <td>
                                                        <b>Função: </b><?php echo h($v['FUNCAO']['DS_FUNCAO']) ?> - <b>Serviço: </b><?php echo h($v['SERVICO']['DS_SERVICO']) ?>
                                                    </td>
                                                    <td>
                                                         <img src="/siscel/img/bt_apagar.gif" id="" onclick="Instituicao.excluirContato('<?php echo h($v['RelacionamentoContatoInsLabServico']['CO_SEQ_CONTATO_INST_LAB']); ?>');"/>
                                                         <img src="/siscel/img/bt_lapis.gif" id="" onclick="Instituicao.editarContato('<?php echo h($arrInstituicao['INSTITUICAOLAB']['CD_INST_LAB']); ?>',<?php echo h($v['RelacionamentoContatoInsLabServico']['CO_SEQ_CONTATO_INST_LAB']) ?>);"/>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div>
                                            <table style="width: 100%;border: 0;" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td>
                                                        <b>Email 1: </b><?php echo h($v['RelacionamentoContatoInsLabServico']['DS_EMAIL_PRINCIPAL']) ?>
                                                    </td>
                                                    <td title="<?php echo h($v[0]['TELEFONES']); ?>" colspan="2">
                                                        <b>Telefones:</b> <?php echo substr(h($v[0]['TELEFONES']), 0, 120).' ...'; ?>
                                                    </td>
                                                    <td></td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </td>
                            </tr>                                                       
                        <?php
                        }
                    }
                    ?>                    
                <tbody>
            </table>
        </div>
    </div>
   
</div>
<script type="text/javascript">
    $(document).ready(function(){
        Instituicao.init();
        Servico.init();
    });
</script>